﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PloobsEngine.SceneControl;
using PloobsEngine.Physics;
using PloobsEngine.Modelo;
using PloobsEngine.Material;
using PloobsEngine.Engine;
using PloobsEngine.Physics.Bepu;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using PloobsEngine.Cameras;
using PloobsEngine.Input;
using PloobsEngine.Light;

namespace PloobsProjectTemplate.Screens
{
    /// <summary>
    /// Basic Forward Screen
    /// </summary>
    public class Menu : IScene
    {
        IModelo mXWing;
        /// <summary>
        /// Sets the world and render technich.
        /// </summary>
        /// <param name="renderTech">The render tech.</param>
        /// <param name="world">The world.</param>
        protected override void SetWorldAndRenderTechnich(out IRenderTechnic renderTech, out IWorld world)
        {
            ///create the IWorld
            world = new IWorld(new BepuPhysicWorld(+0.97f, true, 1), new SimpleCuller());
            

            ///Create the deferred technich
            ForwardRenderTecnichDescription desc = new ForwardRenderTecnichDescription();
            renderTech = new ForwardRenderTecnich(desc);
        }

        /// <summary>
        /// Load content for the screen.
        /// </summary>
        /// <param name="GraphicInfo"></param>
        /// <param name="factory"></param>
        /// <param name="contentManager"></param>
        protected override void LoadContent(GraphicInfo GraphicInfo, GraphicFactory factory, IContentManager contentManager)
        {
            base.LoadContent(GraphicInfo, factory, contentManager);

            mXWing = new SimpleModel(factory, "XWing");
     
            TriangleMeshObject tmesh = new TriangleMeshObject(mXWing, Vector3.Zero, Matrix.Identity, Vector3.One);
           
            IShader shader = new ForwardXNABasicShader(new ForwardXNABasicShaderDescription(Color.Gray,Color.Red,Color.Yellow,50f,1f,true,true,true));
            
            IMaterial fmaterial = new ForwardMaterial(shader);            
            
            XWing xWing = new XWing(tmesh, fmaterial, mXWing);
            
            this.World.AddObject(xWing);

            
            this.World.CameraManager.AddCamera(new CameraFollowObject(xWing, new Vector3(1, 0, -1)));

            SimpleConcreteKeyboardInputPlayable ik1 = new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS, Keys.Space, g1, InputMask.GMENU);
            this.BindInput(ik1);

            SimpleConcreteKeyboardInputPlayable ik2 = new SimpleConcreteKeyboardInputPlayable(StateKey.PRESS, Keys.Tab, g2, InputMask.GMENU);
            this.BindInput(ik2);  
        }

        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        /// <summary>
        /// This is called when the screen should draw itself.
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="render"></param>
        protected override void Draw(GameTime gameTime, RenderHelper render)
        {
            base.Draw(gameTime, render);

            ///Draw some text on the screen
            render.RenderTextComplete("MENU", new Vector2(GraphicInfo.Viewport.Width - 315, 15), Color.White, Matrix.Identity);
        }

        public void g1(InputPlayableKeyBoard ipk)
        {
            ScreenManager.RemoveScreen(this);
            ScreenManager.AddScreen(new Game());
        }

        public void g2(InputPlayableKeyBoard ipk)
        {
            ScreenManager.RemoveScreen(this);
            ScreenManager.AddScreen(new InsideDeathStar());
        }


    }
}
